package com.tangfh.train.batch.service;

//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.core.date.DateTime;
//import cn.hutool.core.util.ObjectUtil;
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
//import com.tangfh.train.common.resp.PageResp;
//import com.tangfh.train.common.util.SnowUtil;
//import com.tangfh.train.batch.domain.Member;
//import com.tangfh.train.batch.domain.MemberExample;
//import com.tangfh.train.batch.mapper.MemberMapper;
//import com.tangfh.train.batch.req.MemberQueryReq;
//import com.tangfh.train.batch.req.MemberSaveReq;
//import com.tangfh.train.batch.resp.MemberQueryResp;
//import jakarta.annotation.Resource;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//
//@Service
//public class MemberService {
//
//    private static final Logger LOG = LoggerFactory.getLogger(MemberService.class);
//
//    @Resource
//    private MemberMapper memberMapper;
//
//    public void save(MemberSaveReq req) {
//        DateTime now = DateTime.now();
//        Member member = BeanUtil.copyProperties(req, Member.class);
//        if (ObjectUtil.isNull(member.getId())) {
//            member.setId(SnowUtil.getSnowflakeNextId());
//            member.setCreateTime(now);
//            member.setUpdateTime(now);
//            memberMapper.insert(member);
//        } else {
//            member.setUpdateTime(now);
//            memberMapper.updateByPrimaryKey(member);
//        }
//    }
//
//    public PageResp<MemberQueryResp> queryList(MemberQueryReq req) {
//        MemberExample memberExample = new MemberExample();
//        memberExample.setOrderByClause("id desc");
//        MemberExample.Criteria criteria = memberExample.createCriteria();
//
//        LOG.info("查询页码：{}", req.getPage());
//        LOG.info("每页条数：{}", req.getSize());
//        PageHelper.startPage(req.getPage(), req.getSize());
//        List<Member> memberList = memberMapper.selectByExample(memberExample);
//
//        PageInfo<Member> pageInfo = new PageInfo<>(memberList);
//        LOG.info("总行数：{}", pageInfo.getTotal());
//        LOG.info("总页数：{}", pageInfo.getPages());
//
//        List<MemberQueryResp> list = BeanUtil.copyToList(memberList, MemberQueryResp.class);
//
//        PageResp<MemberQueryResp> pageResp = new PageResp<>();
//        pageResp.setTotal(pageInfo.getTotal());
//        pageResp.setList(list);
//        return pageResp;
//    }
//
//    public void delete(Long id) {
//        memberMapper.deleteByPrimaryKey(id);
//    }
//}
